﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using WcfServiceLibrary1;
using System.Configuration;
using System.ServiceModel.Configuration;
using DotNETX.CommonWcfClient;

namespace Client
{
    public partial class Form1 : Form
    {
        
        CommonClient<IService1> service = null;

        public Form1()
        {

            InitializeComponent();
            string ip = "localhost";
            string port = "4502";
            service = new CommonClient<IService1>("WcfServiceLibrary1.IService1", string.Format("net.tcp://{0}:{1}/", ip, port));
            service.MaxAliveTrustedTimeSpan = (1000 * 10 * 1);
            service.SetCheckAliveMethod("GetData", 1);
            service.IsKeepAliveEnabled = true;
            service.ProxyOpened += (s, e) =>
            {
                Action act = () =>
                {
                    label4.Text = "opend";
                };
                if (label4.InvokeRequired)
                    label4.Invoke(act);
                else
                    act();
            };
            service.ProxyFaulted += (s, e) =>
            {
                Action act = () =>
                {
                    label4.Text = "faulted";
                };
                if (label4.InvokeRequired)
                    label4.Invoke(act);
                else
                    act();
            };

        }
        int count = 1;
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                label2.Text = service.Proxy.GetData(count++);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
